<template>
	<view class="changePwd_two">
		<view class="tit">设置新密码</view>
		<view class="tip">请输入以字母开头8位数以上的密码</view>
		<view class="psw">
			<view class="new_psw">
				<text>新密码</text>
				<input type="password" placeholder="请输入新密码" v-model="password">
			</view>
			<view class="new_psw">
				<text>确认新密码</text>
				<input type="password" placeholder="再次输入新密码" v-model="repassword">
			</view>
		</view>
		<button style="background-color: #00B2CA; color: #FFFFFF;" type="default" @click="confirm">确认</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password: '',
				repassword: ''
			}
		},
		onLoad() {

		},
		methods: {
			//提示
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			//提交
			confirm() {
				let passwordReg = /^[a-zA-Z]\w{5,17}$/
				let passwordCheck = RegExp(passwordReg).test(this.password)
				let rePasswordReg = /^[a-zA-Z]\w{5,17}$/
				let rePasswordCheck = RegExp(rePasswordReg).test(this.repassword)
				let that = this
				let userInfo = uni.getStorageSync('userInfo')
				if (!passwordCheck || this.password == '') {
					this.showToast('密码不符合要求')
				} else if (!rePasswordCheck || this.repassword == '') {
					this.showToast('请再次输入密码')
				} else if (this.password != this.repassword) {
					this.showToast('两次密码输入不一致')
				} else {
					uni.request({
						url: this.$serverUrl + 'ftUsers/updatePwd',
						data: {
							"id": userInfo.id,
							"password": this.password
						},
						method: 'POST',
						success: (res) => {
							if (res.data.success) {
								that.showToast('密码修改成功')
							} else {
								that.showToast('密码修改失败')
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	.changePwd_two {
		margin: 88upx 36upx;
	}

	.tit {
		font-weight: bold;
		letter-spacing: 3upx;
		color: #333333;
		font-size: 36upx;
	}

	.tip {
		color: #666666;
		font-size: 30upx;
		margin-top: 26upx;
		margin-bottom: 52upx;
	}

	.new_psw {
		height: 124upx;
		display: flex;
		align-items: center;
	}

	.new_psw text {
		width: 30%;
	}

	button {
		background-color: #00B2CA;
		color: #FFFFFF;
		margin-top: 88upx;
	}
</style>
